import { ref } from 'vue'
import { defineStore } from 'pinia'
import { ExitLogin } from '@/apis/login'
import { getLinkGroup } from "@/apis/linkGroup"
import { delLinkShort, getLinkList } from '@/apis/link'

export const useUserStore = defineStore('User', () => {
  const Token = ref('1')
  // 退出登录
  const exitLogin = async() =>{
    const res = await ExitLogin()
    if (res.success) {
      ElMessage.success("退出登录成功")
    }
  }
  // 获取短链接分组
  const LinkGroup = ref([])
  const getGroup = async() =>{
    const res = await getLinkGroup()
    LinkGroup.value = res.data
  }
  // 短链接
  const LinkList = ref([])
  const getLinkList1 = async(gid)=>{
    const res = await getLinkList(gid)
    LinkList.value=res.data
  }
  const delLink = async(data) =>{
    const res = await delLinkShort(data)
    await getLinkList1(data.gid)
    if (res.success){
      ElMessage.success("删除成功")
    }
  }

  return { Token, exitLogin, LinkGroup, getGroup, LinkList, getLinkList1, delLink }
}, {
  persist: true,
})
